<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增打卡功能')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-in-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">您的打卡位置：</label>
            <div class="col-sm-8">
                <input id="cLocation" name="cLocation" class="form-control" type="text" readonly>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.1&key=2259bc6df9de7be84bf366425c7ef42b"></script>
<script type="text/javascript">
    var prefix = ctx + "ruoyi/in"
    $("#form-in-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-in-add').serialize());
        }
    }

    $("input[name='cTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
</script>
<script type="text/javascript">
    var map = new AMap.Map('container', {
        resizeEnable: true
    });
    AMap.plugin('AMap.Geolocation', function () {
        var geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,//是否使用高精度定位，默认:true
            timeout: 10000,          //超过10秒后停止定位，默认：5s
            buttonPosition: 'RB',    //定位按钮的停靠位置
            buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
            zoomToAccuracy: true,   //定位成功后是否自动调整地图视野到定位点

        });
        map.addControl(geolocation);
        geolocation.getCurrentPosition(function (status, result) {
            if (status === 'complete') {
                onComplete(result)
            } else {
                onError(result)
            }
        });
    });

    //解析定位结果
    function onComplete(data) {
        // document.getElementById('status').innerHTML='定位成功'
        address = [data.position.getLng(), data.position.getLat()];
        var geocoder = new AMap.Geocoder({
            // city: "010"//城市，默认：“全国”
        });
        geocoder.getAddress(address, function (status, result) {
            if (status === 'complete') {
                //处理正确返回的地址
                $('#cLocation').val(result.regeocode.formattedAddress);
            } else {
                //失败返回的的值
                alert('定位失败');
            }
        })
    }

    //解析定位错误信息
    function onError(data) {
        alert('定位失败');
    }

</script>
</body>
</html>